package com.kejiguan.ui.presenter;

import com.android.volley.error.VolleyError;
import com.android.volley.response.Response;
import com.kejiguan.ui.model.ExhibitionNeItem;
import com.kejiguan.ui.request.GsonRequest;
import com.kejiguan.ui.request.RequestUtil;
import com.kejiguan.ui.response.ActivationExhibitionResponse;
import com.kejiguan.ui.response.AlarmResponse;
import com.kejiguan.ui.response.QueryUnActivationExhibitionResponse;
import com.kejiguan.ui.util.CacheDataUtil;
import com.kejiguan.ui.util.CommonDate;
import com.kejiguan.ui.util.DateFormatUtil;

import org.greenrobot.eventbus.EventBus;

import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by YYY on 16/7/18.
 */
public class ActivationExhibitionPresenter extends BaseActivityPresenter {


    public void queryUnActivationExhibitions() {
        long currentTime = System.currentTimeMillis();
        String currentDate = String.valueOf(currentTime);
        try {
            currentDate = DateFormatUtil.longToString(currentTime, "yyyyMMdd");
        } catch (ParseException e) {
            e.printStackTrace();
        }


        Map<String, String> params = new HashMap<>();
        params.put("requestCode", "714");
        params.put("messageId", currentDate + "S" + currentTime);
        params.put("systemCode", CommonDate.SystemCode);
        params.put("userName", CacheDataUtil.getInstance().getmUser().getUserName());
        params.put("operType", "queryList");
        params.put("exhibitionState", "unusing");

        final GsonRequest<QueryUnActivationExhibitionResponse> request = new GsonRequest("queryUnActivationExhibitions", QueryUnActivationExhibitionResponse.class, new Response.Listener<QueryUnActivationExhibitionResponse>() {
            @Override
            public void onResponse(QueryUnActivationExhibitionResponse response) {

                response.initDatas();
                EventBus.getDefault().post(response);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });

        RequestUtil.sendRequest(mContext, params, request);
    }

    public void activationExhibitions(ExhibitionNeItem exhibitionNeItem,String exhibitionAreaId) {
        long currentTime = System.currentTimeMillis();
        String currentDate = String.valueOf(currentTime);
        try {
            currentDate = DateFormatUtil.longToString(currentTime, "yyyyMMdd");
        } catch (ParseException e) {
            e.printStackTrace();
        }


        Map<String, String> params = new HashMap<>();
        params.put("requestCode", "714");
        params.put("messageId", currentDate + "S" + currentTime);
        params.put("systemCode", CommonDate.SystemCode);
        params.put("userName", CacheDataUtil.getInstance().getmUser().getUserName());
        params.put("operType", "add");
        params.put("exhibitionId", exhibitionNeItem.getExhibitionId());
        params.put("exhibitionAreaId", exhibitionAreaId);
        params.put("exhibitionName", exhibitionNeItem.getExhibitionName());
        params.put("exhibitionState", "exit");
        params.put("exhibitionNote", "");
        params.put("resources", exhibitionNeItem.getResource());


        final GsonRequest<ActivationExhibitionResponse> request = new GsonRequest("queryUnActivationExhibitions", ActivationExhibitionResponse.class, new Response.Listener<ActivationExhibitionResponse>() {
            @Override
            public void onResponse(ActivationExhibitionResponse response) {

                EventBus.getDefault().post(response);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                ActivationExhibitionResponse response=new ActivationExhibitionResponse();
                response.setRetCode("9999");
                response.setRetCode(error.getMessage());
                EventBus.getDefault().post(response);
            }
        });

        RequestUtil.sendRequest(mContext, params, request);
    }
}
